<?php
$user = $session->read('Auth.User');
?>


<?php
if (isset($user)) :
// Display User Icon / Username
if ($user['prefix'] == ITS_PREFIX) {
    echo $html->image('icon/its_head_user.png');
} elseif ($user['prefix'] == SUPPLIER_PREFIX) {
    echo $html->image('icon/supplier_user.png');
} elseif ($user['prefix'] == CUST_PREFIX) {
    if ($user['is_head_user']) {
        echo $form->create(null, array('url' => array('controller' => 'users', 'action' => 'change_view_site'), 'class' => 'inline', 'id' => 'viewSiteForm'));
        echo 'Site : ' . $form->select('view_site', $this->requestAction('sites/site_list/'. $user['customer_id']), $user['site_id'], 
            array('id' => 'linkViewSite', 'name' => 'data[view_site]'), false);
        echo $form->end();
        echo '&nbsp;|&nbsp;' . $html->image('icon/cust_head_user.png');
    } else {
        echo 'Site : ' . $session->read('Vmi.site_name');
        echo '&nbsp;|&nbsp;' . $html->image('icon/cust_user.png');
    }
}
echo '&nbsp;' . $html->link($user['username'], '/users/profile/' . $user['id']) . ' | ';

// Display Log out | Back to ITS | Back to Vendor
$from_its_user = isset($user['Extend']['from_its_user']) && $user['Extend']['from_its_user'] == true;
$from_supplier = isset($user['Extend']['from_supplier']) && $user['Extend']['from_supplier'] == true;
if ($from_supplier && $user['prefix'] == CUST_PREFIX) {
    echo $html->link('Back to Vendor', '/supplier_admins/customer_back_to_supplier');
} elseif ($from_its_user && $user['prefix'] == CUST_PREFIX) {
    echo $html->link('Back to ITS', '/its_admins/cust_back_to_its');
} elseif ($from_its_user && $user['prefix'] == SUPPLIER_PREFIX) {
    echo $html->link('Back to ITS', '/its_admins/supplier_back_to_its');
} else {
    echo $html->link('Log out', '/users/logout');
} ?>
&nbsp;
<?php if ($user['prefix'] == CUST_PREFIX && isset($user['is_head_user']) && $user['is_head_user'] == true) : ?>
<script type="text/javascript">
    // Cust Head User เลือก Site ที่ต้องการดู
    $j("#linkViewSite").bind("change", function() {
        $j("#viewSiteForm").submit();
    });
</script>
<?php endif; ?>
<?php endif; ?>
